package com.cc.dao.impl;

import com.cc.dao.BaseDao;
import com.cc.dao.DepartmentDao;
import com.cc.entity.Department;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * @author CC
 * @version 1.0
 * @description: TODO
 * @date 2025/4/21 9:55
 */
public class DepartmentDaoImpl extends BaseDao implements DepartmentDao {
    @Override
    public List<Department> getDepartmentList() {
        List<Department> departmentList = new ArrayList<>();
        String sql = "select * from department";
        ResultSet resultSet = executeQuery(sql);
        if (resultSet != null) {
            try {
                while (resultSet.next()){
                    Department department = new Department();
                    department.setId(resultSet.getInt("id"));
                    department.setDeptName(resultSet.getString("dept_name"));
                    department.setDescription(resultSet.getString("description"));
                    departmentList.add(department);
                }
            } catch (SQLException e) {
                throw new RuntimeException(e);
            } finally {
                closedAll(resultSet);
            }
        }

        return departmentList;
    }
}
